<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class WeChatDoctorInfo extends Model
{
	const DR_TYPE_WAIKE = 1;

	const DR_TYPE_NEIKE = 2;

	public static $DRTYPE = [
		self::DR_TYPE_WAIKE => '外科医生',
		self::DR_TYPE_NEIKE => '内科医生'
	];

    protected $table = 'wechat_doctor_infos';

    protected $fillable = [
    	'name',
        'headimg',  //头像
    	'job_title', //职称
    	'dr_type',	//医生类型
        'hospital', //所属医院
        'section',  //所属科室
    	'resume',	//简历
    	'ticket',	//二维码ticket
    	'wechat_doctor_id'
    ];

    protected $appends = [
        'dr_type_desc'
    ];

    public function wechatDoctor(){
        return $this->hasOne('App\Models\WeChatDoctor', 'id','wechat_doctor_id');
    }

    public function messages(){
        return $this->hasMany('App\Models\Message', 'wechat_doctor_info_id');
    }

    public function getDrTypeDescAttribute(){
       if(array_key_exists('dr_type',$this->attributes)){
            return $this->attributes['dr_type_desc']=self::$DRTYPE[$this->attributes['dr_type']];
        }
    }
}
